custom document layouts with y-prosemirror #13
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The following commit allows y-prosemirror to work with documents with forced, custom layouts. An example of this is a document with a required title, with the schema defined as
content: "title block+"
.Previously, it was assumed that an empty ProseMirror document is a single paragraph node, with content size of 2. As a result, when ProseMirror initializes an empty document with a custom layout (with content size > 2), the sync-plugin erroneously triggers a call to
binding._prosemirrorChanged
even though the initial content has not changed.Because of this, yjs will not be able to initialize a serialized document correctly with
Y.applyUpdate(ydoc, ystate)
: instead of merging the nodes fromystate
and the empty nodes created by the ProseMirror layout, it will duplicate the nodes. For example, instead of["title", "paragraph"]
, yjs will initialize the document to["title", "paragraph", "title", "paragraph"]
.To calculate the size of an empty ProseMirror document with any custom layout, we use
view.state.doc
to obtain the node describing the schema (layout) and callcreateAndFill().content.size
(ProseMirror documentation here). We then use this constant instead of 2 in the comparison forchangedInitialContent
.